function dlgdata = FcnCreateSystemButtons(dlgfig, dlgdata, commonGeom)
%FCNCREATESYSTEMBUTTONS creates system buttons
%
%   Inputs:
%     dlgfig      handle of dialog figure
%     dlgdata     dialog data
%     commonGeom  common geometry like text height, ...
%
%   Outputs:
%     dlgdata     dialog data
%
%   Syntax:
%     dlgdata = FcnCreateSystemButtons(dlgfig, dlgdata, commonGeom)
%
%   Example:
%
%
%   See also:
%
% 
%   Author(s): Xiaobiao Huang
%   Copyright 2013-2020 The Xiaobiao Studio.
%   $Revision: 1.0.0.0 $  $Date: 05-Jul-2013 19:37:19 $

figPos      = get(dlgfig,'Position');
sheetPos    = commonGeom.sheetPos;
width       = commonGeom.sysButtonWidth;
height      = commonGeom.sysButtonHeight;
buttonDelta = commonGeom.sysButtonDelta;
Children = dlgdata.children;

%******************************************************************************
% Place dSPACE logo
%******************************************************************************
cx = sheetPos(1)+ buttonDelta;
cy = commonGeom.figBottomEdgeBuffer + commonGeom.sysButton_SheetDelta;
xb_create_logo(dlgfig,cx,cy);

%******************************************************************************
% Place button.
%******************************************************************************
totalButtonWidth = (width * 4) + (buttonDelta * 3);
sheetEdge = sheetPos(1) + sheetPos(3);

cx = sheetEdge - totalButtonWidth;
cy = commonGeom.figBottomEdgeBuffer;

%******************************************************************************
% Place ok button.
%******************************************************************************
Children.OK = uicontrol( ...
    'Parent',            dlgfig,...
    'ToolTipString',     'Write data to block and close dialog',...
    'String',            'OK',...
    'Horizontalalign',   'center',...
    'Position',          [cx cy width height]);

%******************************************************************************
% Place cancel button.
%******************************************************************************
cx = cx + width + buttonDelta;
Children.Cancel = uicontrol( ...
    'Parent',            dlgfig,...
    'ToolTipString',     'Close dialog but do not write data to block',...
    'String',            'Cancel',...
    'Horizontalalign',   'center',...
    'Position',          [cx cy width height]);


%******************************************************************************
% Place help button.
%******************************************************************************
cx = cx + width + buttonDelta;
Children.Help = uicontrol( ...
    'Parent',            dlgfig,...
    'ToolTipString',     'Open associated help document',...
    'String',            'Help',...
    'Enable',            'on',...
    'Horizontalalign',   'center',...
    'Position',          [cx cy width height]);

%******************************************************************************
% Place Apply button.
%******************************************************************************
cx = cx + width + buttonDelta;
Children.Apply = uicontrol( ...
    'Parent',            dlgfig,...
    'ToolTipString',     'Write data to block but do not close dialog',...
    'String',            'Apply',...
    'Horizontalalign',   'center',...
    'Position',          [cx cy width height]);
  
%******************************************************************************
% Place toolbar icons
%******************************************************************************
hToolbar = uitoolbar(dlgfig);
defaultColor = get(0,'DefaultUicontrolBackgroundColor');

%******************************************************************************
% Place Data Dictionary Manager button.
%******************************************************************************
cData = tl_get_icon('DDMan_20x20', 'BackgroundColor', defaultColor);
hPushbutton = uipushtool(hToolbar,'CData',cData, 'Separator', 'on');
set(hPushbutton, 'Enable', 'on', ...
    'ToolTipString', 'Open Data Dictionary Manager');
Children.Dsddman = hPushbutton;


%******************************************************************************
% Place Property Manager button.
%******************************************************************************
cData = tl_get_icon('PropMan_20x20', 'BackgroundColor', defaultColor);
hPushbutton = uipushtool(hToolbar,'CData',cData);
set(hPushbutton, 'Enable', 'on', ...
    'ToolTipString', 'Open Property Manager');
Children.Propman = hPushbutton;

%******************************************************************************
% Place Switch to Simulink block paramters dialog button.
%******************************************************************************
cData = tl_get_icon('Simulink_20x20', 'BackgroundColor', defaultColor);
hPushbutton = uipushtool(hToolbar,'CData',cData);
set(hPushbutton, 'Enable', 'on', ...
    'ToolTipString', 'Switch to Simulink block parameters dialog');
Children.Propman = hPushbutton;

%******************************************************************************
% Place Refresh button.
%******************************************************************************
cData = tl_get_icon('Refresh_20x20', 'BackgroundColor', defaultColor);
hPushbutton = uipushtool(hToolbar,'CData',cData);
set(hPushbutton, 'Enable', 'on', ...
    'ToolTipString', 'Refresh');
Children.Refresh = hPushbutton;

%******************************************************************************
% Place show message browser button.
%******************************************************************************
cData = tl_get_icon('MsgBrowser_20x20', 'BackgroundColor', defaultColor);
hPushbutton = uipushtool(hToolbar,'CData',cData);
set(hPushbutton, 'Enable', 'on', ...
    'ToolTipString', 'Open dSPACE Message Browser');
Children.ShowBrowser = hPushbutton;


%******************************************************************************
% Place status label.
%******************************************************************************
cx = commonGeom.figSideEdgeBuffer;
cy = commonGeom.sysButton_SheetDelta;
Children.StatusLabel = uicontrol( ...
    'Parent',            dlgfig,...
    'Style',             'text', ...
    'Horizontalalign',   'left',...
    'UserData',          struct('defaultString','Ready'),...
    'Position',          [cx cy figPos(3)-2*commonGeom.figSideEdgeBuffer commonGeom.textHeight]);

%******************************************************************************
% Place TransformLink hyperlink.
%******************************************************************************
cx = commonGeom.figSideEdgeBuffer;
cy = figPos(4) - 30;
Children.TransformLink = uicontrol( ...
    'Parent',            dlgfig,...
    'Style',             'text', ...
    'Horizontalalign',   'left',...
    'UserData',          struct('defaultString','Ready'),...
    'Position',          [cx cy figPos(3)-2*commonGeom.figSideEdgeBuffer commonGeom.textHeight]);


dlgdata.children = Children;

end % end of function  FcnCreateSystemButtons
